package com.ylbh.modules.notice.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ylbh.common.pojo.notice.dto.ArticleDTO;
import com.ylbh.common.pojo.notice.vo.ArticleClassVO;
import com.ylbh.common.utils.PageDTO;
import com.ylbh.common.utils.PageUtils;
import com.ylbh.modules.notice.entity.ShoppingArticle;
import com.ylbh.modules.notice.mapper.ShoppingArticleMapper;
import com.ylbh.modules.notice.service.ShoppingArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Date;
import java.util.List;


@Service("shoppingArticleService")
public class ShoppingArticleServiceImpl extends ServiceImpl<ShoppingArticleMapper, ShoppingArticle> implements ShoppingArticleService {

    @Autowired
    private ShoppingArticleMapper shoppingArticleMapper;

    /**
     * 商城公告列表
     * @return
     */
    @Override
    public PageUtils queryNoticeList(PageDTO pageDTO) {
        Page<Integer> page = new Page<>(pageDTO.getPage(), pageDTO.getLimit());
        List<ShoppingArticle> list = shoppingArticleMapper.selectNoticeList(page);
        return new PageUtils(new Page<ShoppingArticle>().setTotal(page.getTotal()).setRecords(list));
    }

    /**
     * 删除公告
     * @param ids
     */
    @Override
    public void removeNoticeById(List<String> ids) {
        shoppingArticleMapper.updateDeleteById(ids);
    }

    /**
     * 公告详情
     * @param id
     * @return
     */
    @Override
    public ShoppingArticle getNoticeById(String id) {
        return shoppingArticleMapper.selectById(id);
    }

    /**
     * 修改公告
     * @param articleDTO
     */
    @Override
    public void modifyNoticeById(ArticleDTO articleDTO) {
        shoppingArticleMapper.updateArticleById(articleDTO);
    }

    /**
     * 新增公告
     * @param articleDTO
     */
    @Override
    public void addNotice(ArticleDTO articleDTO) {
        articleDTO.setAddTime(new Date());
        shoppingArticleMapper.insertArticle(articleDTO);
    }

    /**
     * 公告分类
     * @return
     */
    @Override
    public List<ArticleClassVO> getArticleClass() {
        return shoppingArticleMapper.selectArticleClass();
    }
}
